package lms;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.imageio.ImageIO;

public class Utils {
	
	public static Image getDefault(int w, int h) {
		Image bImage = null;
		try {
			bImage = ImageIO.read(new File("res/default.jpg"));// AssassinsCreed002.jpg
		} catch (IOException ex) {
			System.out.print("Cannot load search picture"); // handle
															// exception...
		}

		return changeSize(bImage, w, h);
	}

	// public methods

	public static Image changeSize(Image original, int w, int h) {
		final BufferedImage scaled = new BufferedImage(w, h,
				BufferedImage.TYPE_INT_ARGB);
		final Graphics2D g2d = scaled.createGraphics();
		g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
				RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g2d.drawImage(original, 0, 0, w, h, 0, 0, original.getWidth(null),
				original.getHeight(null), null);
		g2d.dispose();
		return scaled;
	}
	
	public static String md5(String input) {

		String md5 = null;

		if (null == input)
			return null;

		try {

			// Create MessageDigest object for MD5
			MessageDigest digest = MessageDigest.getInstance("MD5");

			// Update input string in message digest
			digest.update(input.getBytes(), 0, input.length());

			// Converts message digest value in base 16 (hex)
			md5 = new BigInteger(1, digest.digest()).toString(16);

		} catch (NoSuchAlgorithmException e) {

			e.printStackTrace();
		}
		return md5;
	}
	
	


}
